package com.clas.liu.myapplication.presenter.impl;

import android.os.Message;

import com.clas.liu.myapplication.model.event.BaseEvent;
import com.clas.liu.myapplication.model.event.UserEvent;
import com.clas.liu.myapplication.model.impl.BaseFragmentModel;
import com.clas.liu.myapplication.model.impl.UserModel;
import com.clas.liu.myapplication.presenter.i.IUserPresenter;
import com.clas.liu.myapplication.view.fragment.impl.BaseFragment;
import com.clas.liu.myapplication.view.fragment.impl.UserFragment;

/**
 * Created by liu on 2019/5/5.
 */

public class UserFragmentPresenter extends BaseFragmentPresenter<UserModel,UserFragment,UserEvent> implements IUserPresenter {

    public UserFragmentPresenter(UserFragment view) {
        super(view);
    }

    @Override
    public void getInfos(int userId, int type,int page_no,int page_size) {
        mModel.getInfos(userId,type,page_no,page_size);
    }

    @Override
    public void infoDelete(int id) {
        mModel.infoDelete(id);
    }
    @Override
    public void infoSettled(int id) {
        mModel.infoSettled(id);
    }

    @Override
    protected UserModel getModel(BaseFragmentModel.OnEventReceiveListener listener) {
        return new UserModel(this);
    }

    @Override
    public void eventReceiveOnUiThread(Message msg) {

    }

    @Override
    public void eventReceive(UserEvent event, int what) {
        if (what == UserEvent.GET_USER_INFO_OK) {
            mView.infoReturn(event.getRoot().getCode(),event.getRoot().getData());
        }else if (what == UserEvent.GET_USER_INFO_FAIL) {
            mView.FailBecauseNetReturn(what);
        }else if (what==UserEvent.DELETE_INFO_OK) {
            mView.deleteReturn(event.getBaseRoot().getCode());
        }else if (what==UserEvent.SET_INFO_SETTLED_OK) {
            mView.deleteReturn(event.getBaseRoot().getCode());
        }else {
            mView.FailBecauseNetReturn(what);
        }
    }
}
